<template>
  <div>
    <keep-alive>
      <router-view ref="component" v-if="$route.meta.keepAlive"></router-view>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"></router-view>
  </div>
</template>

<script>
import dingMixin from  '@/mixins/ding'
export default {
  data () {
    return {
      
    };
  },
  components: {},
  mixins: [dingMixin],
  watch: {
    $route (to, from) {
      let id = this.$route.query.id;
      let type = this.$route.query.type;
      if(to.name === 'letter' && (from.name === 'letter-mobileHandleList' || from.name === 'letter-handleList') && type === '1' ) {
        this.$router.replace({ name: from.name , params: { id: this.$route.query.id }})
        return
      }
      if(to.name === 'letter' && (from.name === 'letter-mobileList' || from.name === 'letter-list') && type === '2' ) {
        this.$router.replace({ name: from.name , params: { id: this.$route.query.id }})
        return
      }
      if(to.name === 'letter' && id && type && type === '1') this.$router.replace({ name: !this.isPC() ? 'letter-mobileHandleList' : 'letter-handleList' , params: { id: this.$route.query.id }})
      if(to.name === 'letter' && id && type && type === '2') this.$router.replace({ name: !this.isPC() ? 'letter-mobileList' : 'letter-list' , params: { id: this.$route.query.id }})
    }
  },
  mounted () {
    this.getDingConfig().then(config =>{
      this.dingConfig = config;
      this.dingLogin(config.corpId, () => {
        this.getAuthority()
      });
      this.run_dd_config();
    })
  },
  methods: {
    async getAuthority() {
      let authority = await this.$httpN.postB('petition/authority/asd')
      if(authority.userLevel === '1' || authority.userLevel === '2') {
        this.$router.replace({ name: !this.isPC() ? 'letter-mobileHandleList' : 'letter-handleList'})
      } else {
        this.$router.replace({ name: 'letter-rules'})
      }
    }
  }
}
</script>

<style lang='scss' scoped>
</style>